package cn.tedu.signin.management.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.tedu.common.enumerator.ServiceCode;
import cn.tedu.common.ex.ServiceException;
import cn.tedu.common.pojo.authentication.CurrentPrincipal;
import cn.tedu.signin.management.dao.persist.repository.singInRepository;
import cn.tedu.signin.management.pojo.entity.SingIn;
import cn.tedu.signin.management.pojo.param.SingInAddNew;
import cn.tedu.signin.management.pojo.vo.SingInVO;
import cn.tedu.signin.management.service.SingInService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Service
@Slf4j
public class SingInServiceImpl implements SingInService {
    @Autowired
    private singInRepository singInRepository;

    @Override
    public void insert(CurrentPrincipal currentPrincipal, SingInAddNew singInAddNew,Long serialNumber) {

        SingInVO select = singInRepository.select(serialNumber);
        System.out.println(select);
        if (select!=null){
            String message = "订单已签到，服务器忙，请稍后再尝试！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_INSERT, message);
        }

        SingIn sing = new SingIn();

        BeanUtils.copyProperties(singInAddNew,sing);
        sing.setStaffId(currentPrincipal.getId());
        sing.setStatus(1);
        sing.setSerialNumber(serialNumber);

        int insert = singInRepository.insert(sing);

        if (insert!=1){
            String message = "签到失败，服务器忙，请稍后再尝试！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_INSERT, message);
        }




    }

    @Override
    public List<SingInVO> serlectList() {
        return singInRepository.serlectList();
    }
}
